<template>
<div class="sidebar">
  <el-menu
  class="sidebar-el-menu"
  :default-active="onRoutes"
  :collapse="collapse"
  background-color="#334256"
  text-color="#ffffff"
  active-text-color="#20a0ff"
  router>
 <template v-for="(item,index) in items">
   <template>
     <el-menu-item :index="item.index" :key="item.index">
       <i :class="item.icon"></i>
       {{item.title}}
     </el-menu-item>
   </template>
 </template>
  </el-menu>
</div>
</template>

<script>
export default {
  name: "Aside",
  data(){
    return{
      collapse:false,
      items:[
        {
          icon:'el-icon-s-promotion',
          index:'info',
          title:'系统首页'
        },
        {
          icon:'el-icon-s-promotion',
          index:'consumer',
          title:'用户管理'
        },
        {
          icon:'el-icon-s-promotion',
          index:'singer',
          title:'歌手管理'
        },
        {
          icon:'el-icon-s-promotion',
          index:'song',
          title:'歌曲管理'
        }
        ,
        {
          icon:'el-icon-s-promotion',
          index:'songlist',
          title:'歌单管理'
        }
      ]
    }
  },
  mounted() {
    this.$bus.$on('collapse',msg=>{
       this.collapse=msg
    })
  },
  computed:{
    //监听导航栏变化
    onRoutes(){
      return this.$route.path.replace('/','')
    }
  }
}
</script>

<style scoped>
.sidebar{
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  background-color: #334256;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar{
  width: 0;
}
.sidebar >ul{
  height: 100%;
}
.sidebar-el-menu:not(.el-menu--collapse){
  width: 150px;

}
</style>
